package com.wenlong.agricultural.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wenlong.agricultural.pojo.CommodityInfo;
import com.wenlong.agricultural.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author 苏文龙
 * @version 1.0
 */
@Controller
@RequestMapping("/agricultural")
public class PageShowController {
    @Autowired
    private CommodityService commodityService;

    @RequestMapping("/goByPageShow")
    public String goByPageShow() {
        return "byPageShow";
    }

    @RequestMapping("/processPageShow")
    public ModelAndView processPageShow(ModelAndView model, @RequestParam(value = "cur", defaultValue = "1") String cur) {
        Page<CommodityInfo> page = commodityService.getCommoditiesByBage(Long.parseLong(cur), 4L);
        model.addObject("page", page);
        model.setViewName("byPageShow");
        return model;
    }


    @GetMapping("/testPageObject")
    @ResponseBody
    public Page testPageObject() {
        return commodityService.getCommoditiesByBage(2L, 5L);
    }
}
